<?php

	$name      = $_GET['name'];
	$password  = $_GET['password'];
	$newpass   = $_GET['password1'];
	
	$dbhost   = 'localhost';
	$dbuser   = 'root';
	$dbpass   = 'root';
	$database = 'sb';

	$conn  = mysqli_connect($dbhost,$dbuser,$dbpass,$database);

	if(!$conn){
		exit('数据库连接失败');
	}
	
	$sql    = "SELECT * FROM lm WHERE name = '$name' ";
	
	$retval = mysqli_query($conn,$sql);

	$row = mysqli_fetch_row($retval);
	

	if($row !=''){
		header("Location:./try015.html");
		exit;
	}
	
	if(!preg_match("/^[a-zA-Z]{4,12}$/",$name)) {
		header("Location:./try011.html");
		exit;
	}
	
	if(!preg_match("/^\w{6,20}$/",$password)) {
		header("Location:./try012.html");
		exit;
	}
		
	
	if($password != $newpass){
			header("Location:./try013.html");
		}else{
			header("Location:./try014.html");
			$sql = "INSERT INTO lm(name,password)VALUES('$name','$password')";
			$retval = mysqli_query($conn,$sql);
		}
		
		
		if(!$retval){
			exit('无法写入数据'.mysqli_error($conn));
		}
		mysqli_close($conn);
		
		
	?>